home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / FLAT.ZIP / FLATADD.C < prev    next >
C/C++ Source or Header  |  1993-06-21  |  12KB  |  341 lines

  1. #define WIN31
  2. #include <windows.h>
  3. /* For the fancy looking Borland dialog box routines */
  4. #ifdef USES_BWCC
  5. #include <bwcc.h>
  6. #endif
  7. #include "flatm.h"
  8. #pragma hdrstop
  9. #include "flatadd.h"
  10. #include "flatdata.h"
  11. #include <dos.h>
  12. #include <stdlib.h>
  13. #include <ctype.h>
  14. #ifdef USES_MEMCHECK
  15. /* Memory checking routines  by StratosWare Corp. */
  16. #include "\wmemchec\memcheck.h"
  17. #endif
  18.  
  19. /*--------------------------------------------
  20. -
  21. -         FLATADD.C for Flat Windows Program
  22. -
  23. -        Use a editing dialog box to add, edit
  24. -          display, or delete a data record
  25. -
  26. -               Dennis R. Fischer
  27. -                 Denam Systems
  28. -          1115 Madison St. NE  Suite 226
  29. -              Salem, Oregon  97303
  30. -
  31. -             CompuServe 70405,1422
  32. -        Internet 70405.1422@compuserve.com
  33. -
  34. -        Developed with Borland 3.1 Compiler
  35. -
  36. -     Free for the taking but please give credit
  37. -                where credit is do
  38. -
  39. ----------------------------------------------*/
  40.  
  41.  
  42.  
  43. #define SetPushButton(hDlg, idControl) \
  44.     PostMessage(GetDlgItem(hDlg, idControl), BM_SETSTYLE, BS_PUSHBUTTON, 1L);
  45. #define SetDefPushButton(hDlg, idControl) \
  46.     PostMessage(GetDlgItem(hDlg, idControl), BM_SETSTYLE, BS_DEFPUSHBUTTON, 1L);
  47.  
  48.  
  49. BOOL CALLBACK _export ProcessSaleProc(HWND, UINT, WPARAM, LPARAM);
  50.  
  51. BOOL ProcessSale(HWND hW)
  52. {
  53.     /* Create a dialog box */
  54.     FARPROC fpAdd;
  55.     BOOL bUseIt;
  56.  
  57.     fpAdd = MakeProcInstance(ProcessSaleProc, GetInstance());
  58.     if (fpAdd) {
  59.         bUseIt = DialogBox(GetInstance(), "DLG_ADD", hW, fpAdd);
  60.         FreeProcInstance(fpAdd);
  61.     }
  62.     return bUseIt;
  63. }  /* ProcessSale */
  64.  
  65. #pragma argsused
  66. BOOL CALLBACK _export ProcessSaleProc(HWND hDlg,
  67.                                                                             UINT message,
  68.                                                                             WPARAM wParam,
  69.                                                                             LPARAM lParam) {
  70.     struct date dt;
  71.     char ts[41];
  72.   char ts2[6];
  73.  
  74.     switch(message) {
  75.         case WM_INITDIALOG:
  76.             switch (GetWork()) {
  77.                 case DoEdit : SetWindowText(hDlg, "Edit Sales"); break;
  78.                 case DoNew  : SetWindowText(hDlg, "New Sale"); break;
  79.         case DoDelete:
  80.                 case DoView : if (GetWork() == DoView) {
  81.                                 SetWindowText(hDlg, "View Sales");
  82.                                                 EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
  83.                                             }
  84.                                             else {
  85.                                                 SetWindowText(hDlg, "Delete Sale");
  86.                                                 SetPushButton(hDlg, IDOK);
  87.                         SetDefPushButton(hDlg, IDCANCEL);
  88.                                                 EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
  89.                                             }
  90.                                             /* turn off all editing fields so
  91.                                                  user can't tamper with them
  92.                       */
  93.                                             EnableWindow(GetDlgItem(hDlg, DLG_INVOICE), FALSE);
  94.                                             EnableWindow(GetDlgItem(hDlg, DLG_COMPANY), FALSE);
  95.                                             EnableWindow(GetDlgItem(hDlg, DLG_NAME), FALSE);
  96.                                             EnableWindow(GetDlgItem(hDlg, DLG_ADDRESS1), FALSE);
  97.                                             EnableWindow(GetDlgItem(hDlg, DLG_ADDRESS2), FALSE);
  98.                                             EnableWindow(GetDlgItem(hDlg, DLG_CITY), FALSE);
  99.                                             EnableWindow(GetDlgItem(hDlg, DLG_STATE), FALSE);
  100.                                             EnableWindow(GetDlgItem(hDlg, DLG_ZIP), FALSE);
  101.                                             EnableWindow(GetDlgItem(hDlg, DLG_COUNTRY), FALSE);
  102.                                             EnableWindow(GetDlgItem(hDlg, DLG_PRODUCT), FALSE);
  103.                                             EnableWindow(GetDlgItem(hDlg, DLG_PRICE), FALSE);
  104.                                             EnableWindow(GetDlgItem(hDlg, DLG_SOLDVERSION), FALSE);
  105.                                             EnableWindow(GetDlgItem(hDlg, DLG_UPDATEVERSION), FALSE);
  106.                                             EnableWindow(GetDlgItem(hDlg, DLG_DATEINPUT1), FALSE);
  107.                                             EnableWindow(GetDlgItem(hDlg, DLG_DATEINPUT2), FALSE);
  108.                                             EnableWindow(GetDlgItem(hDlg, DLG_DATEINPUT3), FALSE);
  109.                                             break;
  110.         default     : SetWindowText(hDlg, "Error"); break;
  111.       }
  112.             switch (GetWork()) {
  113.                 case DoNew :
  114.                     /* system date */
  115.                     getdate(&dt);
  116.                     /* Make sure input boxes are clear */
  117.                     SetDlgItemText(hDlg, DLG_INVOICE, "");
  118.                     SetDlgItemText(hDlg, DLG_NAME, "");
  119.                     SetDlgItemText(hDlg, DLG_COMPANY, "");
  120.                     SetDlgItemText(hDlg, DLG_ADDRESS1, "");
  121.                     SetDlgItemText(hDlg, DLG_ADDRESS2, "");
  122.                     SetDlgItemText(hDlg, DLG_CITY, "");
  123.                     SetDlgItemText(hDlg, DLG_STATE, "");
  124.                     SetDlgItemText(hDlg, DLG_ZIP, "");
  125.                     SetDlgItemText(hDlg, DLG_COUNTRY, "USA");
  126.           /* You can put your default info here */
  127.                     SetDlgItemText(hDlg, DLG_PRODUCT, "Nag");
  128.                     SetDlgItemText(hDlg, DLG_PRICE, "20.00");
  129.                     SetDlgItemText(hDlg, DLG_SOLDVERSION, "");
  130.                     SetDlgItemText(hDlg, DLG_UPDATEVERSION, "");
  131.                     itoa(dt.da_mon, ts, 10);
  132.                     SetDlgItemText(hDlg, DLG_DATEINPUT1, ts);
  133.                     itoa(dt.da_day, ts, 10);
  134.                     SetDlgItemText(hDlg, DLG_DATEINPUT2, ts);
  135.                     itoa(dt.da_year, ts, 10);
  136.                     SetDlgItemText(hDlg, DLG_DATEINPUT3, ts);
  137.                     break;
  138.                 default:
  139.                     /* If editing, viewing, or deleting a
  140.                          data record, load the dialog box editing
  141.                          fields with the record info
  142.           */
  143.             ts[0]=(char)0;
  144.                     GetInvoice(ts);
  145.                     SetDlgItemText(hDlg, DLG_INVOICE, ts);
  146.                     ts[0]=(char)0;
  147.                     GetName(ts);
  148.                     SetDlgItemText(hDlg, DLG_NAME, ts);
  149.                     ts[0]=(char)0;
  150.                     GetCompany(ts);
  151.                     SetDlgItemText(hDlg, DLG_COMPANY, ts);
  152.                     ts[0]=(char)0;
  153.                     GetAddress1(ts);
  154.                     SetDlgItemText(hDlg, DLG_ADDRESS1, ts);
  155.                     ts[0]=(char)0;
  156.                     GetAddress2(ts);
  157.                     SetDlgItemText(hDlg, DLG_ADDRESS2, ts);
  158.                     ts[0]=(char)0;
  159.                     GetCity(ts);
  160.                     SetDlgItemText(hDlg, DLG_CITY, ts);
  161.                     ts[0]=(char)0;
  162.                     GetState(ts);
  163.                     SetDlgItemText(hDlg, DLG_STATE, ts);
  164.                     ts[0]=(char)0;
  165.                     GetZip(ts);
  166.                     SetDlgItemText(hDlg, DLG_ZIP, ts);
  167.                     ts[0]=(char)0;
  168.                     GetCountry(ts);
  169.                     SetDlgItemText(hDlg, DLG_COUNTRY, ts);
  170.                     ts[0]=(char)0;
  171.                     GetProduct(ts);
  172.                     SetDlgItemText(hDlg, DLG_PRODUCT, ts);
  173.                     ts[0]=(char)0;
  174.                     GetPriceDollar(ts);
  175.                     lstrcat(ts, ".");
  176.           GetPriceCent(ts);
  177.                     SetDlgItemText(hDlg, DLG_PRICE, ts);
  178.                     ts[0]=(char)0;
  179.                     GetSoldVersion(ts);
  180.                     SetDlgItemText(hDlg, DLG_SOLDVERSION, ts);
  181.                     ts[0]=(char)0;
  182.                     GetUpdateVersion(ts);
  183.                     SetDlgItemText(hDlg, DLG_UPDATEVERSION, ts);
  184.           /* Set the correct date fields by date format */
  185.                     switch (GetDateFormat()){
  186.                         case DayMonYear:
  187.                             ts[0]=(char)0;
  188.                             GetDay(ts);
  189.                             SetDlgItemText(hDlg, DLG_DATEINPUT1, ts);
  190.                             ts[0]=(char)0;
  191.                             GetMonth(ts);
  192.                             SetDlgItemText(hDlg, DLG_DATEINPUT2, ts);
  193.                             ts[0]=(char)0;
  194.                             GetYear(ts);
  195.                             SetDlgItemText(hDlg, DLG_DATEINPUT3, ts);
  196.               break;
  197.                         case YearMonDay:
  198.                             ts[0]=(char)0;
  199.                             GetYear(ts);
  200.                             SetDlgItemText(hDlg, DLG_DATEINPUT1, ts);
  201.                             ts[0]=(char)0;
  202.                             GetMonth(ts);
  203.                             SetDlgItemText(hDlg, DLG_DATEINPUT2, ts);
  204.                             ts[0]=(char)0;
  205.                             GetDay(ts);
  206.                             SetDlgItemText(hDlg, DLG_DATEINPUT3, ts);
  207.               break;
  208.                         default:
  209.                 /* MonDayYear */
  210.                             ts[0]=(char)0;
  211.                             GetMonth(ts);
  212.                             SetDlgItemText(hDlg, DLG_DATEINPUT1, ts);
  213.                             ts[0]=(char)0;
  214.                             GetDay(ts);
  215.                             SetDlgItemText(hDlg, DLG_DATEINPUT2, ts);
  216.                             ts[0]=(char)0;
  217.                             GetYear(ts);
  218.                             SetDlgItemText(hDlg, DLG_DATEINPUT3, ts);
  219.               break;
  220.                     }
  221.                     break;
  222.             }
  223.             /* Set the dialog box date display info for the country */
  224.             switch (GetDateFormat()) {
  225.                 case DayMonYear:
  226.                     SetDlgItemText(hDlg, DLG_DATESTR1, " Day");
  227.                     SetDlgItemText(hDlg, DLG_DATESTR2, " Month");
  228.                     SetDlgItemText(hDlg, DLG_DATESTR2, " Year");
  229.                     break;
  230.                 case YearMonDay:
  231.                     SetDlgItemText(hDlg, DLG_DATESTR1, " Year");
  232.                     SetDlgItemText(hDlg, DLG_DATESTR2, " Month");
  233.                     SetDlgItemText(hDlg, DLG_DATESTR2, " Day");
  234.                     break;
  235.                 default:
  236.             /* MonDayYear format */
  237.                     SetDlgItemText(hDlg, DLG_DATESTR1, " Month");
  238.                     SetDlgItemText(hDlg, DLG_DATESTR2, " Day");
  239.                     SetDlgItemText(hDlg, DLG_DATESTR2, " Year");
  240.                     break;
  241.             }
  242.             /* now set the max input length */
  243.             SendDlgItemMessage(hDlg, DLG_INVOICE, EM_LIMITTEXT, 7, 0L);
  244.             SendDlgItemMessage(hDlg, DLG_NAME, EM_LIMITTEXT, 30, 0L);
  245.             SendDlgItemMessage(hDlg, DLG_COMPANY, EM_LIMITTEXT, 30, 0L);
  246.             SendDlgItemMessage(hDlg, DLG_AD